package chapter04

/**
 * @program lu-scala01
 * @description:  不可变Map
 * @author: zhanglu
 * @create: 2022-04-08 22:16:00
 */
object Lu08_ImmutableMap {

  def main(args: Array[String]): Unit = {
    val m1: Map[String, Int] = Map("a" -> 1, "b" -> 2)
    println(m1)
    println(m1.getClass)

    //遍历
    m1.foreach(print)
    println()
    m1.foreach((kv: (String, Int)) => print(kv._1 + "-" + kv._2 + " "))

    println("=============")

    //访问元素
    for(k <- m1.keys){
      println(s"$k ---> ${m1.get(k).get}")
    }
    println(m1.getOrElse("c", -1))
    println(m1("a"))
//    println(m1("c"))  //error

  }

}
